package com.igeekhome.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeekhome.biz.IBlackListService;
import com.igeekhome.biz.ISessionService;
import com.igeekhome.pojo.AttendanceStatistics;
import com.igeekhome.pojo.BlackList;
import com.igeekhome.pojo.CommonWord;
import com.igeekhome.pojo.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 恶意用户列表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-16
 */
@Controller
@RequestMapping("/blackList")
public class BlackListController {

    @Autowired
    private IBlackListService iBlackListService;
    @Autowired
    private ISessionService iSessionService;

    @RequestMapping("/blackcustomer")
    public String bc(HttpSession session, Model model, @RequestParam("value")String value,@RequestParam("current")Integer current, @RequestParam("size")Integer size){


        IPage<BlackList> page0 =new Page<>(current,size);
        QueryWrapper<BlackList> qw=new QueryWrapper<>();
        qw.like("customerserviceid",value).or().like("customerid", value).or().like("reason", value);
        IPage<BlackList> page1=this.iBlackListService.page(page0,qw);
        List<BlackList> list1 = page1.getRecords();
        session.setAttribute("blcount",this.iBlackListService.count());
        long pagesCount=page1.getPages();
        model.addAttribute("list1",list1);
        model.addAttribute("pagesCount",pagesCount);


        IPage<Session> page =new Page<>(current,size);

        IPage<Session> page2=this.iSessionService.page(page);
        List<Session> list2 = iSessionService.list();
        System.out.println(list2);
        model.addAttribute("list2",list2);



        return "blacklist";
    }

    @RequestMapping("/addsuccess")
    public String addbc(BlackList blackList){
        BlackList b = new BlackList(blackList.getCustomerserviceid(),blackList.getCustomerid(),blackList.getReason());
        System.out.println("添加黑名单成功");
        this.iBlackListService.save(b);

        return "redirect:/blackList/blackcustomer?value=&current=1&size=6";
    }



}

